# Maintainer: Alexey Pavlov <Alexpux@gmail.com>

_realname=gmp
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=6.2.0
pkgrel=1
pkgdesc="A free library for arbitrary precision arithmetic (mingw-w64)"
arch=('any')
url="https://gmplib.org/"
license=('LGPL3' 'GPL')
source=(https://gmplib.org/download/gmp-${pkgver}/${_realname}-${pkgver}.tar.xz{,.sig})
options=('staticlibs')
validpgpkeys=('343C2FF0FBEE5EC2EDBEF399F3599FF828C67298') # Niels Möller <nisse@lysator.liu.se>"
sha256sums=('258e6cd51b3fbdfc185c716d55f82c08aff57df0c6fbd143cf6ed561267a1526'
            'SKIP')

build() {
  cd "${srcdir}/${_realname}-${pkgver}"

  # Build static version
  mkdir -p "${srcdir}/static-${MINGW_CHOST}" && cd "${srcdir}/static-${MINGW_CHOST}"
  ../${_realname}-${pkgver}/configure \
    --build=${MINGW_CHOST} \
    --prefix=${MINGW_PREFIX} \
    --enable-cxx \
    --enable-static \
    --disable-shared
  make

  # Build shared version
  mkdir -p "${srcdir}/shared-${MINGW_CHOST}" && cd "${srcdir}/shared-${MINGW_CHOST}"
  ../${_realname}-${pkgver}/configure --build=${MINGW_CHOST} \
    --prefix=${MINGW_PREFIX} \
    --enable-cxx \
    --disable-static \
    --enable-shared
  make
}

check() {
  cd "${srcdir}/static-${MINGW_CHOST}"
  make check
}

package() {
  cd "${srcdir}/static-${MINGW_CHOST}"
  make DESTDIR="${pkgdir}" install

  cd ${srcdir}/shared-${MINGW_CHOST}
  mkdir -p ${pkgdir}${MINGW_PREFIX}/{bin,lib}
  cp .libs/libgmp*.dll ${pkgdir}${MINGW_PREFIX}/bin/
  cp .libs/libgmp*.dll.a ${pkgdir}${MINGW_PREFIX}/lib/
}
